<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="播种时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sowingTime">
              <a-input v-model="model.sowingTime"placeholder="请输入播种时间" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="含盐量20" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yanErshi">
              <a-input v-model="model.yanErshi"placeholder="请输入含盐量20" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="含盐量40" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yanSishi">
              <a-input v-model="model.yanSishi"placeholder="请输入含盐量40" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="含盐量60" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yanLiushi">
              <a-input v-model="model.yanLiushi"placeholder="请输入含盐量60" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="含盐量80" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yanBashi">
              <a-input v-model="model.yanBashi"placeholder="请输入含盐量80" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="含水量20" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shuiErshi">
              <a-input v-model="model.shuiErshi"placeholder="请输入含水量20" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="含水量40" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shuiSishi">
              <a-input v-model="model.shuiSishi"placeholder="请输入含水量40" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="含水量60" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shuiLiushi">
              <a-input v-model="model.shuiLiushi"placeholder="请输入含水量60" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="含水量80" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shuiBashi">
              <a-input v-model="model.shuiBashi"placeholder="请输入含水量80" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="降雨量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jyl">
              <a-input v-model="model.jyl"placeholder="请输入降雨量" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="持水率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="waterHolding">
              <a-input v-model="model.waterHolding"placeholder="请输入持水率" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="滴灌调整系数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dripirrigation">
              <a-input v-model="model.dripirrigation"placeholder="请输入滴灌调整系数" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="淋洗调整系数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="leaching">
              <a-input v-model="model.leaching"placeholder="请输入淋洗调整系数" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="排盐系数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="saltDischarge">
              <a-input v-model="model.saltDischarge"placeholder="请输入排盐系数" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="容重" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unitWeight">
              <a-input v-model="model.unitWeight"placeholder="请输入容重" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="地下水位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="groundwaterLevel">
              <a-input v-model="model.groundwaterLevel"placeholder="请输入地下水位" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(阶段深度/cm)苗期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="miaoStage">
              <a-input v-model="model.miaoStage"placeholder="请输入(阶段深度/cm)苗期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(阶段深度/cm)花期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="huaStage">
              <a-input v-model="model.huaStage"placeholder="请输入(阶段深度/cm)花期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(阶段深度/cm)蕾期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="leiStage">
              <a-input v-model="model.leiStage"placeholder="请输入(阶段深度/cm)蕾期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(阶段深度/cm)龄期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lingStage">
              <a-input v-model="model.lingStage"placeholder="请输入(阶段深度/cm)龄期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(阶段深度/cm)吐絮期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tuxuStage">
              <a-input v-model="model.tuxuStage"placeholder="请输入(阶段深度/cm)吐絮期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(生育阶段/天)苗期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="miaoStagea">
              <a-input v-model="model.miaoStagea"placeholder="请输入(生育阶段/天)苗期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(生育阶段/天)花期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="huaStagea">
              <a-input v-model="model.huaStagea"placeholder="请输入(生育阶段/天)花期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(生育阶段/天)蕾期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="leiStagea">
              <a-input v-model="model.leiStagea"placeholder="请输入(生育阶段/天)蕾期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(生育阶段/天)龄期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lingStagea">
              <a-input v-model="model.lingStagea"placeholder="请输入(生育阶段/天)龄期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(生育阶段/天)吐絮期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tuxuStagea">
              <a-input v-model="model.tuxuStagea"placeholder="请输入(生育阶段/天)吐絮期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(盐分阈值g/kg)苗期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="miaoStageb">
              <a-input v-model="model.miaoStageb"placeholder="请输入(盐分阈值g/kg)苗期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(盐分阈值g/kg)蕾期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="leiStageb">
              <a-input v-model="model.leiStageb"placeholder="请输入(盐分阈值g/kg)蕾期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(盐分阈值g/kg)花期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="huaStageb">
              <a-input v-model="model.huaStageb"placeholder="请输入(盐分阈值g/kg)花期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(盐分阈值g/kg)龄期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lingStageb">
              <a-input v-model="model.lingStageb"placeholder="请输入(盐分阈值g/kg)龄期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(盐分阈值g/kg)吐絮期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tuxuStageb">
              <a-input v-model="model.tuxuStageb"placeholder="请输入(盐分阈值g/kg)吐絮期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(水分阈值cm3/cm3)苗期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="miaoStagec">
              <a-input v-model="model.miaoStagec"placeholder="请输入(水分阈值cm3/cm3)苗期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(水分阈值cm3/cm3)蕾期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="leiStagec">
              <a-input v-model="model.leiStagec"placeholder="请输入(水分阈值cm3/cm3)蕾期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(水分阈值cm3/cm3)花期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="huaStagec">
              <a-input v-model="model.huaStagec"placeholder="请输入(水分阈值cm3/cm3)花期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(水分阈值cm3/cm3)龄期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lingStagec">
              <a-input v-model="model.lingStagec"placeholder="请输入(水分阈值cm3/cm3)龄期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="(水分阈值cm3/cm3)吐絮期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tuxuStagec">
              <a-input v-model="model.tuxuStagec"placeholder="请输入(水分阈值cm3/cm3)吐絮期" ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: "WfimModelParamsModal",
    components: {
    },
    props:{
      mainId:{
        type:String,
        required:false,
        default:''
      }
    },
    data () {
      return {
        title:"操作",
        width:800,
        visible: false,
        model:{
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/wfim/wfimModel/addWfimModelParams",
          edit: "/wfim/wfimModel/editWfimModelParams",
        }

      }
    },
    created () {
    //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.$refs.form.clearValidate();
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            this.model['mainId'] = this.mainId
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
             return false
          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>
